/*
 * IndividualPropertiePanel.java
 *
 * Created on 11. Juni 2008, 00:52
 */

package twi.query.template.view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;

import twi.query.template.ClassNode;

/**
 *
 * @author  Soeren
 */
public class IndividualPropertiePanel extends javax.swing.JPanel {
    private ArrayList<IndividualSinglePropertyPanel> properties;
	private ClassNode classnode;

    /** Creates new form IndividualPropertiePanel */
    public IndividualPropertiePanel(ClassNode cn, ArrayList<IndividualSinglePropertyPanel> properties) {
        initComponents();
        this.classnode = cn;
        this.properties = properties;
        this.jPanel2.setLayout(new GridBagLayout());
        GridBagConstraints gc = new GridBagConstraints();
        gc.gridheight = 1; gc.gridwidth = 1;
        gc.gridx = 0; gc.gridy = 0;
        gc.fill = GridBagConstraints.BOTH;
        for (int i = 0; i < this.properties.size(); i++){
            this.jPanel2.add(this.properties.get(i), gc);
            gc.gridy++;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jCheckBox_opt = new javax.swing.JCheckBox();
        jCheckBox_edit = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        jCheckBox_as_var = new javax.swing.JCheckBox();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(twi_project.TWI_ProjectApp.class).getContext().getResourceMap(IndividualPropertiePanel.class);
        jCheckBox_opt.setText(resourceMap.getString("jCheckBox_opt.text")); // NOI18N
        jCheckBox_opt.setName("jCheckBox_opt"); // NOI18N
        jCheckBox_opt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_optActionPerformed(evt);
            }
        });

        jCheckBox_edit.setText(resourceMap.getString("jCheckBox_edit.text")); // NOI18N
        jCheckBox_edit.setName("jCheckBox_edit"); // NOI18N
        jCheckBox_edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_editActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Properties"));
        jPanel2.setName("jPanel2"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 246, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 92, Short.MAX_VALUE)
        );

        jCheckBox_as_var.setText(resourceMap.getString("jCheckBox_as_var.text")); // NOI18N
        jCheckBox_as_var.setName("jCheckBox_as_var"); // NOI18N
        jCheckBox_as_var.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_as_varActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jCheckBox_opt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox_edit)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox_as_var)
                .addContainerGap(59, Short.MAX_VALUE))
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox_opt)
                    .addComponent(jCheckBox_edit)
                    .addComponent(jCheckBox_as_var))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void jCheckBox_as_varActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_as_varActionPerformed
	this.classnode.setAsVariable(jCheckBox_as_var.isSelected());
}//GEN-LAST:event_jCheckBox_as_varActionPerformed

private void jCheckBox_optActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_optActionPerformed
	this.classnode.setOptional(jCheckBox_opt.isSelected());
}//GEN-LAST:event_jCheckBox_optActionPerformed

private void jCheckBox_editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_editActionPerformed
	this.classnode.setEditable(jCheckBox_edit.isSelected());
}//GEN-LAST:event_jCheckBox_editActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox jCheckBox_as_var;
    private javax.swing.JCheckBox jCheckBox_edit;
    private javax.swing.JCheckBox jCheckBox_opt;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables

	public ArrayList<IndividualSinglePropertyPanel> getPropertiePanels() {
		return this.properties;
	}

}
